package com.mrobuy.jd.api;

import com.jd.open.api.sdk.JdClient;
import com.jd.open.api.sdk.request.supplier.UserCategory3InfoGetRequest;
import com.jd.open.api.sdk.response.supplier.UserCategory3Dto;
import com.jd.open.api.sdk.response.supplier.UserCategory3InfoGetResponse;
import com.mrobuy.jdvc.entity.VCCategory;

import java.util.ArrayList;
import java.util.List;

/**
 *  获取我的类目列表
 *
 *  jingdong.vc.item.products.find
 *
 *  <url>https://open.jd.com/home/home#/doc/api?apiCateId=86&apiId=1681&apiName=jingdong.vc.item.products.find</url>
 *
 *
 *
 */
public class CategoryFindClient extends JosClient<List<VCCategory>> {

    private UserCategory3InfoGetRequest request=new UserCategory3InfoGetRequest();

    public CategoryFindClient(JdClient client) {
        super(client);
    }

    @Override
    public List<VCCategory> call() throws Exception {

        List<VCCategory> result = new ArrayList<>();

        UserCategory3InfoGetResponse response = client.execute(request);

        LOG.info("Count: " + response.getUserCategory3Info().getUserCategory3Dtos().size());

        for (UserCategory3Dto userCategory3Dto : response.getUserCategory3Info().getUserCategory3Dtos()) {
            VCCategory  vcCategory = new VCCategory();
            vcCategory.setId(Integer.parseInt(userCategory3Dto.getCode()));
            vcCategory.setName(userCategory3Dto.getName());
            vcCategory.setLevel(3);
            result.add(vcCategory);
        }
        return result;
    }
}
